﻿
using System;
using System.Collections.Generic;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;

namespace YouHP.Pages.Member
{
    public class ListLabcheckRecordes : YouHP.Pages.Member.PatientBasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (IsPost) HandlePost();
            else HandleGet();
        }


        protected int LabcheckRecordesCount { get; set; }
        protected List<LabcheckRecordesInfo> LabcheckRecordesList { get; set; }
        protected int PageSize;

        protected void HandleCommon()
        {
            PageSize = 15;
            LabcheckRecordesList = PatientBLL.Instance.GetLabcheckRecordesList(PRInfo.Id);
            LabcheckRecordesCount = LabcheckRecordesList.Count;
        }

        protected void HandlePost()
        {
            string[] dszitemid = Utils.SplitString(RequestTools.GetFormString("recordid"), ",");
            bool succ = true;
            List<int> idlst = new List<int>();
            if (succ)
            {
                if (dszitemid.Length <= 0) succ = false;
                else if (dszitemid.Length > PageSize) succ = false;
            }

            if (succ)
            {
                foreach (string str in dszitemid)
                {
                    int id = Utils.StrToInt(str, -1);
                    if (id <= 0)
                    {
                        succ = false;
                        break;
                    }
                    idlst.Add(id);
                }
            }


            if (succ)
            {
                PatientBLL.Instance.DelLabcheckesRecordes(idlst.ToArray(), PRInfo.Id);
                ResponseHelper.Redirect("ListLabcheckRecordes.aspx");
            }
            else
            {
                this.AddErrLine("删除失败");
            }
        }

        protected void HandleGet()
        {
            int action = RequestTools.GetQueryInt("action", -1);
            if (action == 1) PatientBLL.Instance.MakeGraphLabcheck(PRInfo.Id); 
        }
    }
}